require 'open3'
class Diff
  include Open3
  attr_reader :string1, :string2, :defalut_options

  def initialize(string1, string2)
    @string1 = string1
    @string2 = string2
  end

  def diff
    file1 = tempfile @string1
    file2 = tempfile @string2
    paths = [file1, file2]
    diff = Open3.popen3('diff', *(['-U 10000'] + paths)) { |i, o, e| o.read }
    diff
  end

  def tempfile(string)
    t = Tempfile.new('diff')
    @tempfiles ||=[]
    @tempfiles.push(t)
    t.print(string)
    t.flush
    t.close
    t.path
  end
end
